package team.bluepen.supermarket.service.impl;

import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import team.bluepen.supermarket.entity.User;
import team.bluepen.supermarket.service.impl.utils.UserDetailsImpl;
import team.bluepen.supermarket.service.user.UserInfoService;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 狗崽
 */
@Service
public class UserInfoServiceImpl implements UserInfoService {
    @Override
    public Map<String, String> getInfo() {
        UsernamePasswordAuthenticationToken authentication =
                (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();

        UserDetailsImpl loginUser = (UserDetailsImpl) authentication.getPrincipal();
        User user = loginUser.getUser();
        Map<String, String> map = new HashMap<>();
        map.put("message", "success");
        map.put("username", user.getUsername());
        return map;

    }
}
